#include "CommonOptions.h"
#include "util.h"

bool CommonOptions::serialize(QDomElement& elem, QDomDocument& doc) const {
    Util::serializeUshort(elem, doc, "exptime", expTime);
    Util::serializeUshort(elem, doc, "meastime", idleTime);
    Util::serializeUshort(elem, doc, "ivoltage", ionizationVoltage);
    Util::serializeUshort(elem, doc, "cp", CPVoltage);
    Util::serializeUshort(elem, doc, "ecurrent", emissionCurrent);
    Util::serializeUshort(elem, doc, "hcurrent", heatCurrent);
    Util::serializeUshort(elem, doc, "focus1", focusVoltage1);
    Util::serializeUshort(elem, doc, "focus2", focusVoltage2);
    Util::serializeUshort(elem, doc, "before", beforeTime);
    Util::serializeUshort(elem, doc, "forward", forwardTime);
    Util::serializeUshort(elem, doc, "back", backwardTime);
    Util::serializeBool(elem, doc, "equal", forwardAsBefore);
    return true;
}

bool CommonOptions::deserialize(const QDomElement& elem) {
    if (!Util::deserializeUshort(elem, "exptime", expTime)) return false;
    if (!Util::deserializeUshort(elem, "meastime", idleTime)) return false;
    if (!Util::deserializeUshort(elem, "ivoltage", ionizationVoltage)) return false;
    if (!Util::deserializeUshort(elem, "cp", CPVoltage)) return false;
    if (!Util::deserializeUshort(elem, "ecurrent", emissionCurrent)) return false;
    if (!Util::deserializeUshort(elem, "hcurrent", heatCurrent)) return false;
    if (!Util::deserializeUshort(elem, "focus1", focusVoltage1)) return false;
    if (!Util::deserializeUshort(elem, "focus2", focusVoltage2)) return false;
    if (!Util::deserializeUshort(elem, "before", beforeTime)) return false;
    if (!Util::deserializeUshort(elem, "forward", forwardTime)) return false;
    if (!Util::deserializeUshort(elem, "back", backwardTime)) return false;
    if (!Util::deserializeBool(elem, "equal", forwardAsBefore)) return false;
    return true;
}
